#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;
const int B = 250;

int n, q;
int p[N], tp[N], ip[N], a[N], b[N], tot, id[N], ans[N], nxt[N];
vec pot[N];
bool tg[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, q = in;
	rep(i, 1, n) p[i] = in;
	rep(i, 1, q) tp[i] = in, a[i] = in, b[i] = in;
	rep(l, 1, q) {
		int r = l, qcnt = 0;
		rep(i, 1, n) tg[i] = 0, ip[p[i]] = i;
		for(; r <= q && qcnt <= B; r++) {
			if(tp[r] == 1) tg[a[r]] = true, tg[b[r]] = true, qcnt += 2;
			else tg[a[r]] = true, qcnt++;
		}
		r--; tot = 0;
		rep(i, 1, n) if(tg[i]) id[i] = ++tot, pot[tot].clear();
		rep(i, 1, n) if(tg[i]) {
			int x = i; pot[id[i]].eb(i); x = ip[x]; while(!tg[x]) pot[id[i]].eb(x), x = ip[x];
			nxt[id[x]] = id[i]; reverse(pot[id[i]].begin(), pot[id[i]].end());
		}
		rep(i, l, r) {
			if(tp[i] == 1) { swap(p[a[i]], p[b[i]]); swap(nxt[id[a[i]]], nxt[id[b[i]]]); }
			else {
				int x = id[a[i]], loop = pot[x].size();
				while(nxt[x] != id[a[i]]) x = nxt[x], loop += pot[x].size();
				b[i] %= loop; if(b[i] == 0) { ans[i] = a[i]; continue; }
				x = id[a[i]]; x = nxt[x];
				while(true) {
					if(b[i] <= pot[x].size()) { ans[i] = pot[x][b[i] - 1]; break; }
					else b[i] -= pot[x].size(), x = nxt[x];
				}
			}
		} l = r;
	} rep(i, 1, q) if(tp[i] == 2) printf("%d\n", ans[i]);
	return 0;
}
